package com.computercourse.learning.dao;

import com.computercourse.framework.domain.learning.CicLearningCourse;
import com.computercourse.framework.domain.learning.CicUserNote;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @description:
 * @author: yuanfeng
 * @date: Created in 2020/2/15 4:05 下午
 * @version: 1.0
 */
@Repository
public interface CicUserNoteRepository extends JpaRepository<CicUserNote,String> {

    //根据用户Id和课程Id查询
    List<CicUserNote> findAllByCourseIdOrderByNoteTimeDesc(String courseId);

    //根据用户Id和课程Id查询
    List<CicUserNote> findAllByCourseIdAndPerfectNoteEqualsOrderByModifyTimeDesc(@Param("courseId") String courseId,@Param("perfectNote") Integer perfectNote);

    CicUserNote findByCourseIdAndNoteId(@Param("courseId") String courseId,@Param("noteId") String noteId);

    @Modifying
    @Query(value = "update CicUserNote set perfectNote = 0 where courseId = :courseId and noteId = :noteId")
    int cancelPerfectNote(@Param("courseId") String courseId,@Param("noteId") String noteId);

}
